﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NEmu;
using Super64.Core.CPU;
using System.IO;
using Super64.Core.CPU.MIPS;
using Super64.Core.CPU.MIPS.Interpreter;
using Super64.Core.Memory.Ram;

namespace Super64.Core
{
    public sealed class N64Machine : VirtualMachine
    {
        N64Resources m_Resources;
        N64Memory m_Memory;
        MipsEngine m_Engine;

        public N64Machine()
        {
            m_Memory = new N64Memory(this);
            m_Resources = new N64Resources(this);
            m_Engine = new MipsInterpreter(this);
        }

        protected override bool Boot()
        {
            m_Engine.LoadBootCode(new MemoryStream(m_Resources.CurrentRom.Header.BootCode));
            m_Engine.Run();
            return true;
        }

        protected override void InitializeComponents()
        {
            m_Engine.Initialize();
        }

        public override ResourceManager Resources
        {
            get { return m_Resources; }
        }

        public override NEmu.Memory MachineMemory
        {
            get { return m_Memory; }
        }
    }
}
